<?
include_once("../../php/postgre.php");

$act = '';
if (isset($_POST['act']))
    $act = $_POST['act'];
	
if ($act == 'tampil_laporan'){
	$idskpd = $_POST['idskpd'];
	if(is_numeric($idskpd)){
		echo 'ok___';
		view_data ($idskpd);
	}else{
		echo "error";
	}
}

function view_data($idskpd){
	$tahun = date ('Y');
	$t_prog = get_datas ("select distinct p.id_program, p.nama_program from mus_program p, mus_kegiatan k, mus_usulankecamatan u where u.id_kegiatan=k.id_keg and k.id_program=p.id_program and u.id_skpd=$idskpd and u.tahun=$tahun order by p.id_program");
	$cek_skpd = get_datas ("select distinct u.id_usulankec, u.id_kegiatan, u.kegiatan from mus_usulankecamatan u, mus_rinc_usulan_kec r where u.id_usulankec=r.id_usulankec and u.id_skpd=$idskpd and u.tahun=$tahun and r.status=0 order by u.id_usulankec" );
	foreach ($cek_skpd as $cek){
	$no = 1;
		if($cek['kegiatan'] == 0){
			if (count($t_prog) > 0){
				foreach ($t_prog as $t_p){
					?>
                    <tr><td><?php echo $no; ?></td><td colspan="5"><?php echo $t_p['nama_progran']; ?></td></tr>
                    <?php
						echo $t_p['id_program'];
						$tampil = get_datas ("select distinct u.id_usulankec, k.nama_kegiatan, u.indikator_hasil, u.indikator_program, u.indikator_keluaran, u.target_hasil from mus_usulankecamatan u, mus_rinc_usulan_kec r, mus_kegiatan k, mus_program p where r.id_usulankec=u.id_usulankec and r.status=0 and k.id_keg=u.id_kegiatan and u.id_skpd='$idskpd' and u.tahun='$tahun' and k.id_program=p.id_program and k.id_program = ".$t_p['id_program']." order by u.id_usulankec");
						foreach ($tampil as $tampil){
							?>
                            <tr>
                            	<td>&nbsp;</td><td><?php echo $tampil['nama_kegiatan'];?></td>
                                <td><?php echo $tampil['indikator_program'];?></td>
                                <td><?php echo $tampil['indikator_keluaran'];?></td>
                                <td><?php echo $tampil['indikator_hasil'];?></td>
                                <td><?php echo $tampil['target_hasil'];?></td>
                            </tr>
                            <?php
						}
				}
			}
		}else if ($cek['id_kegiatan'] == 0){
			$sql = get_datas ("select distinct u.id_usulankec, u.indikator_hasil, u.indikator_program, u.indikator_keluaran, u.target_hasil, u.kegiatan from mus_usulankecamatan u, mus_rinc_usulan_kec r where r.id_usulankec=u.id_usulankec and r.status=0 and u.id_skpd='$idskpd' and u.tahun='$tahun' order by u.id_usulankec");
			foreach($sql as $sql){
				?>
                <tr>
                	<td><?php echo $no; ?></td>
                    <td><?php echo $sql ['kegiatan']?></td>
                    <td><?php echo $sql ['indikator_program']?></td>
                    <td><?php echo $sql ['indikator_keluaran']?></td>
                    <td><?php echo $sql ['indikator_hasil']?></td>
                    <td><?php echo $sql ['target_hasil']?></td>
                </tr>
                <?php
			}
		}
            $no++;
	}
}
?>